<?php

defined('BASEPATH') or die('forbidden');

/**
 * 公用模块，此通用模块将是任何访问地址都会执行，而且是第一个执行，优先级高于其它任何方法
 * @author  Karson
 * @name   common.php
 * @since   2013-4-27 23:52:45
 */
class Common_Model extends Model {

    function _init() {
        //判断用户是否在IP黑名单
        if (check_ip(get_ip(), $this->config['ip_ban'])) {
            tips('非常抱歉，你被限制访问。。。', $this->config['ip_ban_text']);
        }
        //判断网站访问状态
        if (!$this->config['site_state']) {
            tips("非常抱歉，{$this->config['sitename']}升级维护中。。。", $this->config['site_state_text']);
        }
        //首次记录访客来源
        $referer = $this->cookie->get('referer');
        $username = $this->cookie->get('username');
        if (!$referer) {
            $referer = $this->input->server("HTTP_REFERER");
            $referer = $referer == '' ? '直接访问' : $referer;
            $this->cookie->set('referer', $referer);
        }
        $begintime = get_unixtime();
        $one = $this->db->one("SELECT COUNT(*) AS num FROM {pre}thread WHERE replytime>{$begintime}");
        $this->view->assign("threadnew", $one['num']);
    }

}